"""
encoding = 'utf-8'
@author : ffine
@time   : 2022-05-04  20:09
@IDE   : PyCharm
@goal   :
"""
from functools import reduce


class People:
	"""
	这是一个人的类
	"""
	def __init__(self, name, age):
		self.name = name
		self.__age = age
		self.cont = 0
		print("People init...")

	def __del__(self):
		print("People del: I am done...")
		
	def __call__(self, *args, **kwargs):
		print(f"{self.name} call...")
		res = self.calculate(*args)
		# print("callable: " , res)
		return res
	
	def __str__(self):
		return f"{self.name} is {self.__age} years old."
	
	def __len__(self):
		return len(self.name)

	def __next__(self):
		if self.__age > self.cont:
			self.cont += 1
			return self.cont
		else:
			raise StopIteration
        
	def __iter__(self):
		return self
	
	def __getitem__(self, item):
		print(f"{self.name} get item...")
		return getattr(self, item)
	
	def __setitem__(self, key, value):
		print(f"{self.name} set item...")
		setattr(self, key, value)
		
	def __delitem__(self, key):
		print(f"{self.name} del item...")
		delattr(self, key)
	
	def __add__(self, other):
		print(f"{self.name} add...")
		if other.__class__ == People:
			return self.name + " love " + other.name+"!"

	def calculate(self, *args):
		print(f"{self.name} calculate...")
		return reduce(lambda x, y: x+y, args)

	